package com.xyb.controller;

import com.xyb.entity.SysUser;
import com.xyb.service.UserService;
import com.xyb.vo.SysUserVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {
    @Resource
    private UserService userService;

    @GetMapping("users/{status}")
    public List<SysUser> selectSysUserListByStatus(@PathVariable("status")  Integer status) {
        return userService.selectSysUserListByStatus(status);
    }

    @GetMapping("user/{userId}")
    public SysUserVo selectSysUserByUserId(@PathVariable("userId") Long userId) {
        return userService.selectSysUserByUserId(userId);
    }

    /**
     * 管理员注册
     * @param sysUserVo
     * @return
     */
    @PostMapping("user")
    public String insertSysUser(@RequestBody @Validated(SysUserVo.insert.class) SysUserVo sysUserVo){
        return userService.insertSysUser(sysUserVo);
    }

    /**
     * 修改用户状态
     * @param sysUserVo
     * @return
     */
    @PutMapping("user/status/{userId}")
    public String updateSysUserStatus(@PathVariable("userId") Long userId,@RequestBody @Validated(SysUserVo.status.class) SysUserVo sysUserVo){
        sysUserVo.setUserId(userId);
        return userService.updateSysUserStatus(sysUserVo);
    }

    /**
     * 修改用户信息
     * @param sysUserVo
     * @return
     */
    @PutMapping("user/{userId}")
    public String updateSysUser(@PathVariable("userId") Long userId,@RequestBody @Validated(SysUserVo.update.class) SysUserVo sysUserVo){
        sysUserVo.setUserId(userId);
        return userService.updateSysUser(sysUserVo);
    }

    @PutMapping("/user/order")
    public String updateSysUserShowOrder(@RequestBody Long[] userIds){
        return userService.updateSysUserShowOrder(userIds);
    }

    /**
     * 删除用户信息
     */
    @DeleteMapping("user/{userId}")
    public String deleteSysUserByUserId(@PathVariable("userId") Long userId){
        return userService.deleteSysUserByUserId(userId);
    }
}
